from django.db import models


class BBsLinks(models.Model):  # 收集页面的链接
    id = models.AutoField(primary_key=True)
    link = models.URLField(unique=True, blank=False, null=False)  # 需要添加
    title = models.CharField(max_length=1000, blank=False, null=False)  # 标题唯一值 需要添加
    adddata = models.DateTimeField(auto_now_add=True)
    linkNum = models.CharField(default='', max_length=20, blank=False, null=False)
    status = models.IntegerField(default=1, blank=True, null=True)  # 状态（由第二步维护更新）：1,录入未检测  2.录入成功 3.录入失败

    def __str__(self):
        return f'id:[{str(self.id)}],{self.title}'

    class Meta:
        verbose_name = '1.链接资源'
        # verbose_name_plural = verbose_name
        ordering = ['-linkNum']


class BBSContent(models.Model):  # 这里的内容定时循环检查(特征：不同的标不同题，有相同的id)
    id = models.AutoField(primary_key=True)
    contentLink = models.OneToOneField(BBsLinks, null=False, blank=False, on_delete=models.CASCADE)
    tbid = models.IntegerField(default='', blank=True, null=True)  # 淘宝的商品id
    keyword = models.CharField(max_length=1000, default='', blank=True, null=True)  # 对比出来的核心词语（通过title和contentWord进行比对）
    contentWord = models.TextField(default='', blank=True, null=True)  # 抓链接前的一段文字进行比对
    status = models.IntegerField(default=1, blank=True,
                                 null=True)  # 状态（由第三步，发企博时候维护更新）：1,默认入库  2.淘宝爬虫完成  3.发帖完成  4.失败状态
    updata = models.DateTimeField(auto_now_add=True)  # 操作更新时间

    def __str__(self):
        return f'核心关键词：{self.keyword} ,原句：{self.keyword} ，时间{self.updata}'

    class Meta:
        verbose_name = '2.帖子内容'
        verbose_name_plural = verbose_name
        ordering = ['-id']


class TbIndex(models.Model):  # 保存淘宝的id，用于联系图片表和评论表
    id = models.AutoField(primary_key=True)
    tbid = models.IntegerField(default=0, blank=False, null=False, unique=True)  # 淘宝的商品id
    tbkURL = models.CharField(max_length=1000, null=True, blank=True, default='')
    tbkShopURL = models.CharField(max_length=1000, null=True, blank=True, default='')

    def __str__(self):
        return f'商品id：{self.tbid}'

    class Meta:
        verbose_name = '3.商品主id表'
        verbose_name_plural = verbose_name


class TbIMG(models.Model):  # 这里的内容定时循环检查
    id = models.AutoField(primary_key=True)
    tbimg_Index = models.ForeignKey('TbIndex', on_delete=models.CASCADE)
    imgSrc = models.CharField(max_length=1000, null=False, unique=True)

    def __str__(self):
        return f'商品图片：{self.imgSrc}'

    class Meta:
        verbose_name = '3.1商品图片表'
        verbose_name_plural = verbose_name


class TbComment(models.Model):  # 这里的内容定时循环检查
    id = models.AutoField(primary_key=True)
    tbComment_Index = models.ForeignKey('TbIndex', on_delete=models.CASCADE)
    commentWord = models.CharField(max_length=4000, null=False)

    def __str__(self):
        return f'商品留言：{self.commentWord}'

    class Meta:
        verbose_name = '3.2商品留言表'
        verbose_name_plural = verbose_name


class TbFirstWord(models.Model):
    id = models.AutoField(primary_key=True)
    firstWord = models.CharField(max_length=1000, null=True, blank=True, default='')

    def __str__(self):
        return f'前缀词：{self.firstWord}'

    class Meta:
        verbose_name = '3.3前缀词表'
        verbose_name_plural = verbose_name


class TbLastWord(models.Model):
    id = models.AutoField(primary_key=True)
    lastWord = models.CharField(max_length=1000, null=True, blank=True, default='')

    def __str__(self):
        return f'前缀词：{self.lastWord}'

    class Meta:
        verbose_name = '3.4后缀词表'
        verbose_name_plural = verbose_name


# 企博账号设置
class QiBoAccount(models.Model):
    qibo_Fk_Discuz = models.ForeignKey('DiscuzAccount', default=0, verbose_name='喵口令基本配置', on_delete=models.DO_NOTHING)
    runStatus = models.BooleanField(verbose_name='是否开启运行', null=False, default=False)
    id = models.AutoField(primary_key=True)
    pid = models.CharField(max_length=1000, null=False, blank=False,
                           default='mm_28964573_303450418_82851750421')  # 淘宝联盟密令 '6e39417a-bc77-3d4d-c2ae-0a51f37d2574'
    apkey = models.CharField(max_length=1000, null=False, blank=False,
                             default='6e39417a-bc77-3d4d-c2ae-0a51f37d2574')  # 喵口令密令
    username = models.CharField(max_length=1000, null=False, blank=False, default='')
    password = models.CharField(max_length=1000, null=False, blank=False, default='')
    bokeeName = models.CharField(max_length=1000, null=False, blank=False, default='')
    title = models.CharField(max_length=1000, null=True, blank=True, default='')
    content = models.CharField(max_length=1000, null=True, blank=True, default='')
    columnName = models.CharField(max_length=1000, null=False, blank=True, default='')  ## 分类名字1
    addType = models.CharField(max_length=1000, null=False, blank=True, default='')  # 分类2
    tags = models.CharField(max_length=1000, null=False, blank=True, default='')  # 标签
    visibility = models.CharField(max_length=1000, null=False, blank=True, default='')  # # 公开方式，保持默认
    brief = models.CharField(max_length=1000, null=False, blank=True, default='')  # # 内容摘要
    commentable = models.CharField(max_length=1000, null=True, blank=True, default='')  # 开启评论，保持默认
    displayControl = models.CharField(max_length=1000, null=False, blank=True, default='')  # 摘要模式，保持默认
    stateNo = models.CharField(max_length=1000, null=False, blank=True, default='')  # 状态码，保持默认
    templateNum = models.IntegerField(default=1, blank=False, null=False, unique=False)  # 使用模板的id
    POSTnum = models.IntegerField(default=1, blank=False, null=False, unique=False)  # 每次发帖次数

    def __str__(self):
        return f'发帖账号配置表：{self.username}'

    class Meta:
        verbose_name = '------企博的账号'
        verbose_name_plural = verbose_name


# discuz账号设置，username是bbs的发帖账号，postusrl是发帖地址，fid是发帖板块，discuziName是参考名称
class DiscuzAccount(models.Model):
    runStatus = models.BooleanField(verbose_name='是否开启运行', null=False, default=False)
    id = models.AutoField(primary_key=True)
    pid = models.CharField(verbose_name='淘宝PID', max_length=1000, null=False, blank=False,
                           default='mm_28964573_303450418_82851750421')  # 淘宝联盟密令 '6e39417a-bc77-3d4d-c2ae-0a51f37d2574'
    tbusername = models.CharField(verbose_name='喵口令绑定的淘宝用户名', max_length=1000, null=False, blank=False,
                                  default='shenhuawade')  # 淘宝联盟密令 '6e39417a-bc77-3d4d-c2ae-0a51f37d2574'
    apkey = models.CharField(verbose_name='喵口令apkey', max_length=1000, null=False, blank=False,
                             default='6e39417a-bc77-3d4d-c2ae-0a51f37d2574')  # 喵口令密令（必须用我自己的账号来发，因为服务器白名单只能在一个账号上设置）
    JDkey_id = models.CharField(verbose_name='京东在喵口令上生成的id', max_length=1000, null=False, blank=False,
                                default='J4765683946244691')  # 喵口令密令（必须用我自己的账号来发，因为服务器白名单只能在一个账号上设置）
    username = models.CharField(max_length=1000, null=False, blank=False, default='怎么样评测')  # discuz发帖账号
    postUrl = models.CharField(max_length=1000, null=False, blank=False,
                               default='https://www.0476y.com/huoche.php?pw=0405qq')  # 发帖地址
    fid = models.CharField(max_length=5, null=False, blank=False, default='57')  # discuz的板块编号，用字符串格式 57
    discuzName = models.CharField(max_length=1000, null=False, blank=False, default='赤峰玉龙社区')  # discuz的网站名称  非必须
    sendNum = models.IntegerField(default=1, blank=False, null=False, unique=False)  # 账号发帖的次数

    def __str__(self):
        return f'{self.discuzName}发帖账号配置表：{self.username}'

    class Meta:
        verbose_name = '------discuz的发帖账号'
        verbose_name_plural = verbose_name


# 运行模式
class RunModel(models.Model):
    id = models.AutoField(primary_key=True)
    modelType = models.IntegerField(default=0, blank=False, null=False)  # 0模式是bbs贴吧模式 1模式是读取自定义字段模式，自己录入内容

    def __str__(self):
        return f'运行模式：{self.modelType}'

    class Meta:
        verbose_name = '*******运行模式'
        verbose_name_plural = verbose_name
        ordering = ['-id']


# 自生产 tbid 和 商品标题
class DIYTitle(models.Model):
    id = models.AutoField(primary_key=True)
    tbid = models.CharField(default='', blank=True, null=True, max_length=30)  # 淘宝的商品id
    title = models.TextField(default='', blank=True, null=True, max_length=60)  # 抓链接前的一段文字进行比对
    status = models.IntegerField(default=1, blank=True,
                                 null=True)  # 状态（由第三步，发企博时候维护更新）：1,默认入库  2.淘宝爬虫完成  3.发帖完成  4.失败状态
    updata = models.DateTimeField(auto_now_add=True)  # 操作更新时间

    def __str__(self):
        return f'id：{self.tbid} ,标题：{self.title} ，时间{self.updata}'

    class Meta:
        verbose_name = '2.DIY Id和标题'
        verbose_name_plural = verbose_name
        ordering = ['-id']


# 京东帖子资源发帖状态存储
class Jdong(models.Model):
    id = models.AutoField(primary_key=True)
    FakeURL = models.CharField(default='', blank=True, null=True, max_length=30)  # 淘宝的商品id
    title = models.TextField(default='', blank=True, null=True, max_length=60, unique=True)  # 抓链接前的一段文字进行比对
    hasPOst = models.BooleanField(verbose_name='发帖状态，false未发，true已发', default=False, blank=True,
                                  null=False)  # 状态（由第三步，发企博时候维护更新）：1,默认入库  2.淘宝爬虫完成  3.发帖完成  4.失败状态

    def __str__(self):
        return f'id：{self.id} ,标题：{self.title}'

    class Meta:
        verbose_name = '京东发帖资源存储'
        verbose_name_plural = verbose_name
        ordering = ['id']


"""重新规划方案"""


class WadeMiaoKouLing(models.Model):  # 一
    id = models.AutoField(primary_key=True)
    pid = models.CharField(verbose_name='喵口令pid', max_length=1000, null=False, blank=False,
                           default='mm_28964573_303450418_82851750421')  # 淘宝联盟密令 '6e39417a-bc77-3d4d-c2ae-0a51f37d2574'
    apkey = models.CharField(max_length=1000, null=False, blank=False,
                             default='6e39417a-bc77-3d4d-c2ae-0a51f37d2574')  # 喵口令密令
    JDkey_id = models.CharField(verbose_name='京东在喵口令上生成的id', max_length=1000, null=False, blank=False,
                                default='J4765683946244691')  # 喵口令密令（必须用我自己的账号来发，因为服务器白名单只能在一个账号上设置）
    tbusername = models.CharField(verbose_name='喵口令绑定的淘宝用户名', max_length=1000, null=False, blank=False,
                                  default='shenhuawade')  # 淘宝联盟密令 '6e39417a-bc77-3d4d-c2ae-0a51f37d2574'

    def __str__(self):
        return f'id：{self.id} ,用户：{self.tbusername}'

    class Meta:
        verbose_name = '喵口令API配置'
        verbose_name_plural = verbose_name
        ordering = ['id']


class WadeQiboAccount(models.Model):  # 多
    id = models.AutoField(primary_key=True)
    username = models.CharField(verbose_name='登陆用户名', max_length=1000, null=False, blank=False,
                                default='11325433@qq.com')
    password = models.CharField(verbose_name='登陆密码', max_length=1000, null=False, blank=False, default='1987wade')
    bokeeName = models.CharField(verbose_name='博客名字', max_length=1000, null=False, blank=False, default='zenmeyangya')
    postNum = models.IntegerField(verbose_name='一次发帖数量', default=0, blank=False, null=False)
    runStatus = models.BooleanField(verbose_name='是否开启运行', null=False, default=False)
    # ForeignKey


    def __str__(self):
        return f'id：{self.id} ,用户：{self.username}'

    class Meta:
        verbose_name = '企博账户发帖配置'
        verbose_name_plural = verbose_name
        ordering = ['id']


class WadeBBSAccount(models.Model):  # 多
    id = models.AutoField(primary_key=True)
    username = models.CharField(verbose_name='博客用户名', max_length=1000, null=False, blank=False,
                                default='怎么样评测')
    postUrl = models.CharField(max_length=1000, null=False, blank=False,
                               default='https://www.0476y.com/huoche.php?pw=0405qq')  # 发帖地址
    fid = models.CharField(max_length=5, null=False, blank=False, default='57')  # discuz的板块编号，用字符串格式 57
    discuzName = models.CharField(max_length=1000, null=False, blank=False, default='赤峰玉龙社区')  # discuz的网站名称  非必须
    postNum = models.IntegerField(default=1, blank=False, null=False, unique=False)  # 账号发帖的次数
    runStatus = models.BooleanField(verbose_name='是否开启运行', null=False, default=False)

    def __str__(self):
        return f'id：{self.id} ,用户：{self.username}'

    class Meta:
        verbose_name = '论坛账户发帖配置'
        verbose_name_plural = verbose_name
        ordering = ['id']
